package com.erbao.dp.flyweight;

/**
 * @author CaoBaoYin
 * @since 21/9/16 17:39
 */
public class TestString {
    public static void main(String[] args) {
        String s1 = "abc";
        String s2 = "abc";
        String s3 = new String("abc");
        String s4 = new String("abc");

        System.out.println(s1 == s2);//true 指向常量池 引用一样
        System.out.println(s1 == s3);//false
        System.out.println(s3 == s4);//false 指向堆中的对象不是一个
        System.out.println(s3.intern() ==  s1);//true intern也是指向常量池
        System.out.println(s3.intern() == s4.intern());//true
    }
}
